<template>
  <!-- 叫号列表 -->
  <el-dialog title="呼叫患者" :visible="value" width="700px" custom-class="dialog-box" @close="onClose" @open="onOpen" :close-on-click-modal="false" :append-to-body="true">
    <table class="table-box">
      <thead>
        <tr>
          <th>排号</th>
          <th>姓名</th>
          <th>性别</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody>
        <tr v-for="(item,index) in tableList" :key="index">
          <td>{{item.sourceCode}}</td>
          <td>{{item.patientInfo.name}}</td>
          <td>{{item.patientInfo.sex|toSex}}</td>
          <td>
            <el-link type="primary" @click="onCall(item)">呼叫</el-link>
            &nbsp;
            <el-link  type="primary" @click="onCancel(item,index)">过号</el-link>
          </td>
        </tr>
      </tbody>
    </table>
    <br>
    <div v-if="tableList.length == 0" style="color:#999;padding:10px 0;text-align:center;">
      <i class="iconfont iconwushuju" style="font-size:40px;"></i>
      <div>暂无数据</div>
    </div>
    <br>
    <pager v-model="pager" @change-pagenum="getData"></pager>
  </el-dialog>
</template>
<script>
export default {
  props: ["value", "doctorId"],
  data() {
    return {
      tableList: [],
      pager: { pageSize: 10, pageNum: 1, total: 0 }
    };
  },
  methods: {
    onCancel(obj, index) {
      let th = this;
      th.$confirm(`确定过号?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true
      })
        .then(() => {
          let j = {
            id: obj.id,
            callStaus: 0
          };
          th.$api.callOrderpassOrder(j).then(res => {
            if (res.executed) {
              th.$message.success("过号成功");
              th.tableList.splice(index, 1);
            } else {
              th.$message.error(res.message);
            }
          });
        })
        .catch(() => {});
    },
    onCall(obj) {
      let th = this;
      th.$message.success("呼叫完成");
      th.onClose();
      let j = {
        id: obj.id,
        callStaus: 1
      };
      th.$api
        .callOrdercallOrder(j)
        .then(res => {
          if (res.executed) {
          } else {
            th.$message.error(res.message);
          }
        })
        .catch(() => {});
    },
    getData() {
      let th = this;
      let j = {
        dateDay: th.$utils.FormatTime("yyyy-MM-dd", new Date().getTime()),
        doctorId: th.doctorId,
        status:6,
      };
      Object.assign(j, th.pager);
      th.$api.getDoctorRegisterList(j).then(res => {
        if (res.executed) {
          th.tableList = res.dataBody.list;
          th.pager.total = res.dataBody.total;
        }
      });
    },
    onOpen() {
      let th = this;
      th.getData();
    },
    onClose() {
      let th = this;
      th.tableList = [];
      th.pager.pageNum = 1;
      th.pager.total = 0;
      th.$emit("input", false);
    }
  }
};
</script>